package com.its.goods.controller;

import com.its.domain.BaseResult;
import com.its.goods.pojo.Goods;
import com.its.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    //依赖注入Service层属性
    @Autowired
    private GoodsService goodsService;

    //声明单元方法：新增商品
    @PostMapping("/add")
    public BaseResult addGoods(@RequestBody Goods goods){
        return BaseResult.ok(goodsService.addGoods(goods));
    }

    //声明单元方法：删除商品信息
    @DeleteMapping("/delete")
    public BaseResult deleteGoods(Integer gid){
        return BaseResult.ok(goodsService.deleteGoods(gid));
    }

    //声明单元方法：修改商品信息
    @PutMapping("/update")
    public BaseResult updateGoods(@RequestBody Goods goods){
        return BaseResult.ok(goodsService.updateGoods(goods));
    }

    //声明单元方法：根据关键字查询商品信息
    @GetMapping("/findByKeyword")
    public BaseResult selectGoodsByKeyword(@RequestParam String keyword){
        return BaseResult.ok(goodsService.selectGoodsByKeyword(keyword));
    }

    //根据ID查询商品信息
    @GetMapping("/findById")
    public BaseResult selectGoodsById(Integer gid){
        return BaseResult.ok(goodsService.selectGoodsByIdService(gid));
    }

    //声明单元方法：分页查询所有商品信息
    @GetMapping("/search")
    public BaseResult getAllGoods(Integer page,Integer size){
        return BaseResult.ok(goodsService.selectAllGoods(page, size));
    }

    //声明单元方法：无条件查询所有商品信息
    @GetMapping("/findAll")
    public BaseResult findAllGoods(){
        return BaseResult.ok(goodsService.findAllGoods());
    }
}
